<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-10-14 18:06:56
 * @LastEditTime: 2019-10-16 18:21:42
 * @LastEditors: Please set LastEditors
 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <button onclick="getRandomSSQ()">机选一注双色球</button>


    <script type="text/javascript">
        let ssqArrs = getAllSSQRedArray();

        function getAllSSQRedArray() {
            let arr = [];
            for (let index = 1; index < 34; index++) {
                arr.push(index);
            }
            // console.log(arr)
            return arr;
        }

        /**
         * 
         * @param {获取几注} number 
         * @param {已选择的数组} selectArr 
         */
        function getRandomRedNumber(number, selectArr) {
            let rst = [];
            for (let index = 0; index < number; index++) {
                rst.push(getRandomSSQRedNumber(selectArr, 0))
            }
            return rst;
        }


        function getRandomSSQRedNumber(selectArr, selectNumber) {
            let rst = [];
            //未加异常校验
            let length = selectArr && selectArr.length ? selectArr.length : 0;
            let randomTime = length >= 6 ? 6: 0;
            let number = 0;
            // console.log("randomTime=",randomTime)
            if (randomTime) {
                for (let index = 0; number < 6; index++) {
                    var idx = Math.floor(Math.random() * selectArr.length);
                    let obj = selectArr[idx];
                    if (rst.includes(obj)) {
                        continue;
                    } else {
                        number++;
                        rst.push(obj);
                        if (number == 6) {
                            break;
                        }
                    }
                }
            } else {
                // 选择的数据小于6个
                rst = selectArr;
                //去除已存在的
                let filterArr = ssqArrs.filter((value, index, ssqArrs) => {
                    return !selectArr.includes(value);
                })
                // console.log("filterArr=",filterArr)
                for (let index = 0; index < 6-length; index++) {
                    var idx = Math.floor(Math.random() * filterArr.length);
                    let obj = filterArr[idx];
                    rst.push(obj);
                }

            }
            return rst;
        }
        function getRandomSSQ(){
            console.log(getRandomSSQRedNumber([1,4,9,10,13,14,15,16,20,25,29,32],1).sort())
            
        }
    </script>
</body>

</html>